package com.supor.nfc.lib.utils;


public class ByteUtil {

    /**
     * 判断数组不为null 或者长度不为0
     *
     * @param bytes 　源
     * @return return true,if byte array is not null;
     */
    public static boolean notNull(byte[] bytes) {
        if (bytes == null || bytes.length <= 0) {
            return false;
        }
        return true;
    }

    public static int byteArrayToInt(byte[] b) {
        return byteArrayToInt(b, 0);
    }

    private static int byteArrayToInt(byte[] b, int offset) {
        int value = 0;
        int len = Math.min(b.length - offset, 4);
        for (int i = 0; i < len; i++) {
            int shift = (len - 1 - i) * 8;
            value += (b[i + offset] & 0x000000FF) << shift;
        }
        return value;
    }

    public static int computeBodyNum(byte[] data) {
        int num = 0;
        for (byte aData : data) {
            num += aData & 0x000000FF;
        }
        return num;
    }

}
